package com.rchat.pocmini.activity.register;

import com.aso.common.http.delegate.HttpCallbackImpl;
import com.aso.common.http.utils.HttpUtils;
import com.rchat.pocmini.global.AppGlobal;
import com.rchat.pocmini.global.HttpCodeGlobal;
import com.rchat.pocmini.global.RequestParam;
import com.rchat.pocmini.global.UrlsGlobal;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by ljd on 2017/7/27.
 */

public class RegisterModelImpl implements RegisterContract.Model {

    @Override
    public void checkAccount(String account, HttpCallbackImpl callback) {
        Map<String, String> param = new HashMap<>();
        param.put("account", account);
        //body = {"code":2001,"data":{"platform":1,"version":"1.0","enterprise":1,"account":"0707"}}
        String body = RequestParam.requestRootParam(HttpCodeGlobal.REQ_CODE_2001, param);
        HttpUtils.postAsyn(UrlsGlobal.getUrl(UrlsGlobal.CHECK_ACCOUNT), body, callback);
    }

    @Override
    public void getVerificationCode(String phone, HttpCallbackImpl callback) {
        Map<String, String> param = new HashMap<>();
        param.put("mobile", phone);
        param.put("appType", AppGlobal.APPTYPE);
        //body = {"code":2000,"data":{"platform":1,"version":"1.0","enterprise":1,"mobile":"xxxxxxxxxxx","appType":"0"}}
        String body = RequestParam.requestRootParam(HttpCodeGlobal.REQ_CODE_2000, param);
        HttpUtils.postAsyn(UrlsGlobal.getUrl(UrlsGlobal.GET_VERIFICATION_CODE_URL), body, callback);
    }

    @Override
    public void register(String nickName, String userName, String pwd, String pwdConfirm, String verificationCode, String mail, String phone, HttpCallbackImpl callback) {

        Map<String, String> param = new HashMap<>();
        param.put("displayName", nickName);
        param.put("account", userName);
        param.put("password", pwd);
        param.put("identifyCode", verificationCode);
        param.put("email", mail);
        param.put("phone", phone);
        //body = {"code":1012,"data":{"platform":1,"version":"1.0","enterprise":1,"phone":"xxxxxxxxxxx","email":"","account":"111","password":"111111","identifyCode":"333333","displayName":"和1"}}
        String body = RequestParam.requestRootParam(HttpCodeGlobal.REQ_CODE_1012, param);

        HttpUtils.postAsyn(UrlsGlobal.getUrl(UrlsGlobal.REGISTER_URL), body, callback);
    }
}
